package com.yuexunit.mobilenurse.module.SkinTest.presenter.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPObject;
import com.yuexunit.mobilenurse.module.SkinTest.bean.SkinTestDetailBean;
import com.yuexunit.mobilenurse.module.SkinTest.bean.SkinTestListBean;
import com.yuexunit.mobilenurse.module.SkinTest.bean.YXSkinTestDetailBean;
import com.yuexunit.mobilenurse.module.SkinTest.bean.YXSkinTestExecBean;
import com.yuexunit.mobilenurse.module.SkinTest.bean.YXSkinTestListBean;
import com.yuexunit.mobilenurse.module.SkinTest.model.ISkinTestDetailModel;
import com.yuexunit.mobilenurse.module.SkinTest.model.ISkinTestListModel;
import com.yuexunit.mobilenurse.module.SkinTest.presenter.ISkinTestDetailPresenter;
import com.yuexunit.mobilenurse.module.SkinTest.ui.view.ISkinTestDetailView;
import com.yuexunit.mobilenurse.module.SkinTest.ui.view.ISkinTestListView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.ArrayList;
import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/3/14 0014.
 */

public class SkinTestDetailPresenter implements ISkinTestDetailPresenter{
    private ISkinTestDetailView view;
    private ISkinTestDetailModel model;
    SkinTestDetailBean skinTestDetailBean = new SkinTestDetailBean();

    public SkinTestDetailPresenter(ISkinTestDetailView view,ISkinTestDetailModel model)
    {
        this.view = view;
        this.model = model;
    }

    @Override
    public void showSkinTestDetail(String psh) {
        model.getSkinTestDetailData(psh)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("暂无数据");
                               }

                               @Override
                               public void onNext(String result) {

                                   YXSkinTestDetailBean Total = JSON.parseObject(result, YXSkinTestDetailBean.class);
                                   YXSkinTestDetailBean InspectData = Total.getBody();

                                   if ("0".equals(InspectData.getHead().getRet_code())) {
                                       skinTestDetailBean = JSON.parseObject(InspectData.getResponse().getPatinfodetail(), SkinTestDetailBean.class);
                                       view.showSkinTestDetail(skinTestDetailBean);

                                   } else {
                                       ViewInject.toast("暂无数据");
                                   }

                               }
                           }
                );
    }

    @Override
    public void startSkinTest(String Psh, String Pspc, String Pszxr) {
        model.startSkinTest(Psh,Pspc,Pszxr)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("失败"+e.getMessage());
                               }

                               @Override
                               public void onNext(String result) {

                                   YXSkinTestExecBean Total = JSON.parseObject(result, YXSkinTestExecBean.class);
                                   YXSkinTestExecBean InspectData = Total.getBody();
                                   view.startSkinTest(InspectData);

                               }
                           }
                );
    }

    @Override
    public void endSkinTest(String Psh, String Psjg, String Psfhr1, String Psfhsj1, String Psfhr2, String Psfhsj2) {
        model.endSkinTest(Psh,Psjg,Psfhr1,Psfhsj1,Psfhr2,Psfhsj2)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("失败"+e.getMessage());
                               }

                               @Override
                               public void onNext(String result) {

                                   YXSkinTestExecBean Total = JSON.parseObject(result, YXSkinTestExecBean.class);
                                   YXSkinTestExecBean InspectData = Total.getBody();
                                   view.endSkinTest(InspectData);

                               }
                           }
                );
    }
}
